Repository navigation
fix(analytics): use ThreadPoolExecutor for engage pagination so it works on AWS Lambda - #86
Draft
rahul-mixpanel wants to merge 2 commits into
Draft
rahul-mixpanel wants to merge 2 commits into
rahul-mixpanel wants to merge 2 commits into
Conversation
…rks on AWS Lambda multiprocessing.pool.ThreadPool creates POSIX semaphores, which need /dev/shm. AWS Lambda has no /dev/shm, so query_engage/export_people failed with FileNotFoundError while creating the pool. concurrent.futures.ThreadPoolExecutor only uses threading primitives and keeps the same ordering and concurrency. Related to #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge; no actionable new issues were found. Reviews (2) · Last reviewed commit: "fix(analytics): use ThreadPoolExecutor f..." · Reviewed by Greptile |
… on AWS Lambda _dispatch_batches (used by import_events, people_operation and the other import paths) also used multiprocessing.pool.ThreadPool, which fails on Lambda for the same /dev/shm reason. Submit batches to a ThreadPoolExecutor and wait for them on shutdown; the response callback still runs only on success and _send_batch errors stay handled as before. Related to #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On AWS Lambda,
export_people()/query_engage()fail withFileNotFoundError: [Errno 2] No such file or directory, raised while creating amultiprocessing.pool.ThreadPool. The import paths (import_events,import_people,people_operation, group imports via_dispatch_batches) also useThreadPooland would fail the same way.Root cause:
ThreadPoolis built onmultiprocessing.Pool, which creates POSIX semaphores (SemLock) through/dev/shm. Lambda has no/dev/shm, so making the pool fails.Fix: both places now use
concurrent.futures.ThreadPoolExecutor, which only usesthreading:ConcurrentPaginator._concurrent_flatmap(engage pagination) usesexecutor.map. It keeps result order and theread_pool_sizeconcurrency, and still passes worker exceptions to the caller.MixpanelUtils._dispatch_batches(batch imports) submits each batch and waits for all of them withexecutor.shutdown(wait=True). As before,_async_response_handler_callbackruns only after a successful_send_batch, and_send_batcherrors are handled the same way (logged / written toimport_backup.txt, not raised to the caller). Concurrency still comes frompool_size.The public API, output files and request payloads don't change.
Tests
New tests simulate Lambda by making multiprocessing
SemLockcreation raiseFileNotFoundError:tests/test_paginator.py: pages come back in order andfetch_allworks without multiprocessing semaphores.tests/test_dispatch_batches.py: every batch is sent and the response callback runs once per batch.Both Lambda tests fail on
masterand pass with this change. Full suite: 62 passed.Not included
Cancelling queued pages after the first failure (
shutdown(cancel_futures=True)).masterdoesn't do this either, so this PR keeps the current behaviour.Related to #59 · Linear: SDK-378
🤖 Generated with Claude Code